﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QLMBMT
{
    public partial class FrmInHD : DevExpress.XtraEditors.XtraForm
    {
        private SqlDataAdapter da = new SqlDataAdapter();
        private DataSet ds = new DataSet();

        classConnection _classConnection = new classConnection();

        public int STTHOADON;
        public FrmInHD()
        {
            InitializeComponent();
            _classConnection.KetNoiCSDL();
        }

        private void FrmInHD_Load(object sender, EventArgs e)
        {
            rptInHD rpt = new rptInHD();
            dsInHD dsInHD = new dsInHD();
            SqlCommand comm = new SqlCommand();
            comm.Connection = _classConnection.con;
            comm.CommandType = CommandType.Text;
            comm.CommandText = "select bh.STTHOADON, bh.MAHANG, mh.TENHANG,SOLUONGBAN, DONGIABAN,"
                                      + " DVT, VAT, kh.TENKHACHHANG, kh.DIACHIKH, kh.SDTKHACHHANG, nv.TENNHANVIEN,"
                                       +" (SOLUONGBAN * DONGIABAN)+ (SOLUONGBAN * DONGIABAN * VAT /100) as THANHTIEN"
                                +" from BAN_HANG bh"
                                +" left join HOA_DON hd on bh.STTHOADON = hd.STTHOADON"
                                +" left join MAT_HANG mh on bh.MAHANG = mh.MAHANG"
                                +" left join KHACH_HANG kh on hd.MAKHACHHANG = kh.MAKHACHHANG"
                                +" left join NHAN_VIEN nv on nv.MANHANVIEN = hd.MANHANVIEN"
                                + " where bh.STTHOADON = @STTHOADON";
            comm.Parameters.Add("STTHOADON", SqlDbType.Int).Value = STTHOADON;
            comm.ExecuteNonQuery();
            da = new SqlDataAdapter();
            da.SelectCommand = comm;
            da.Fill(ds);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                DataRow item = dsInHD.Tables[0].NewRow();
                item["STTHOADON"] = dr["STTHOADON"];
                item["MAHANG"] = dr["MAHANG"];
                item["TENHANG"] = dr["TENHANG"];
                item["SOLUONGBAN"] = dr["SOLUONGBAN"];
                item["DONGIABAN"] = dr["DONGIABAN"];
                item["DVT"] = dr["DVT"];
                item["VAT"] = dr["VAT"];
                item["TENKHACHHANG"] = dr["TENKHACHHANG"];
                item["DIACHIKH"] = dr["DIACHIKH"];
                item["SDTKHACHHANG"] = dr["SDTKHACHHANG"];
                item["TENNHANVIEN"] = dr["TENNHANVIEN"];
                item["THANHTIEN"] = dr["THANHTIEN"];
                dsInHD.Tables[0].Rows.Add(item);
            }
            rpt.DataSource = dsInHD;
            this.printControl1.PrintingSystem = rpt.PrintingSystem;
            rpt.CreateDocument();
        }
    }
}
